<template>
  <view class="page">
	  <!-- #ifdef MP-WEIXIN-->
	  	<view class="head"><text @click="submit">提交</text></view>
	  <!-- #endif -->
	  <!-- #ifndef MP-WEIXIN-->
		<my-navbar leftText="意见反馈" @leftClick="back" @rightClick="submit" rightText="提交" rightColor="#40AE36"></my-navbar>
	  <!-- #endif -->
      <view class="content">
          <textarea class="textarea" @input="inputAction" :placeholder="place"  placeholder-style="color:#999" auto-height></textarea>
          <u-upload ref="upload" :action="action" max-size="2097152" max-count="3" :auto-upload="true" :header="header" :form-data="{type:1}" name="img" 
		   @on-success="uploadimg" @on-remove="removeimg" ></u-upload>
      </view>
  </view>
</template>

<script>
import {$https} from '@/static/js/request.js';
export default {
    data(){
        return{
            header:'',
            value:'',
            place:'我们想听听你的心声，如果愿意，你可以给我们留下联系方式和意见反馈，我们期待与你的真诚沟通！',
            action: '',
            imgList:[],
        }
    },
	onReady(){
		getApp().setTitle()
	},
    onLoad(){
        this.header = {
			'Authorization': uni.getStorageSync("copartner_token"),
		}
		//上传地址
		this.action = `${getApp().globalData.rootUrl}/partner/uploadFeedImg`
    },
    methods:{
        inputAction(e){
            this.value = e.detail.value;
        },
        uploadimg(opa){
			// console.log(opa)
			this.err = opa
            // this.imgList = opa.map(item=>{
            //     return item.response.data.img_path;
            // })
			this.imgList.push(opa.data.img_path)
        },
		removeimg(index){
			console.log(index)
			this.imgList.splice(index,1)
		},
        submit(){
            if(this.value){
				var params = {
					content:this.value,
				};
				if(this.imgList.length>0){
					Object.assign(params,{img_arr:this.imgList})
				}
                $https('POST','feedback',params,res=>{
                    if(res.data.errcode==0){
                        uni.showToast({
                            title: '提交成功',
							icon:'none',
                            success(){
                                setTimeout(function(){
									// #ifdef H5
										window.history.back(-1);
									// #endif 
									// #ifndef H5
									uni.navigateBack();
									// #endif
                                },2000)
                            }
                        });
                    }else{
                        uni.showToast({
                            title: res.data.errmsg,
                        });
                    }
                })
            }
        },
        back(){
			// #ifdef H5
				window.history.back(-1);
			// #endif 
			// #ifndef H5
			uni.navigateBack();
			// #endif
        }
    }
}
</script>

<style lang="scss" scoped>
.page{
	.head{
		height: 88rpx;
		width: 100%;
		padding:0 30rpx;
		color: $dgreen;
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}
    .content{
        padding:20rpx 30rpx;
        .textarea{
			font-size: 28rpx;
			color:#333333;
            background:#fff;
            padding:10rpx;
            box-sizing: border-box;
            width:100%;
            min-height: 300rpx;
        }
		/deep/.u-list-item{
			border:4rpx dashed #e3e3e3;
		}
    }
}
</style>